package com.xjprojectc.webservice;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.xjprojectc.business.pojo.T_agentaccountinfo;

public class Call{
	private static JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
	private static JaxWsProxyFactoryBean fileFactionryBean = new JaxWsProxyFactoryBean();
	private static IDataAlternately service = null;
	private static IFileAlternately fileService = null;
	static{
		factoryBean.setServiceClass(IDataAlternately.class);
		factoryBean.setAddress("http://222.80.103.52:8089/XJPROJECT/services/DataAlternately?wsdl");
		service = (IDataAlternately) factoryBean.create();
		
		fileFactionryBean.setServiceClass(IFileAlternately.class);
		fileFactionryBean.setAddress("http://222.80.103.52:8089/XJPROJECT/services/FileAlternately?wsdl");
		fileService = (IFileAlternately) fileFactionryBean.create();
	}
	public static IDataAlternately getCall(){
		if(service == null){
			factoryBean.setServiceClass(IDataAlternately.class);
			factoryBean.setAddress("http://222.80.103.52:8089/XJPROJECT/services/DataAlternately?wsdl");
			service = (IDataAlternately) factoryBean.create();
		}
		return service;
	}
	
	public static IFileAlternately getFileCall(){
		if(fileService == null){
			fileFactionryBean.setServiceClass(IFileAlternately.class);
			fileFactionryBean.setAddress("http://222.80.103.52:8089/XJPROJECT/services/FileAlternately?wsdl");
			fileService = (IFileAlternately) fileFactionryBean.create();
		}
		return fileService;
	}
	
	@SuppressWarnings("unchecked")
	public static Map setCallUser(T_agentaccountinfo user){
		Random rdm=new Random();
		StringBuffer logid = new StringBuffer();
		logid.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
		logid.append(rdm.nextInt(90)+10);
		logid.append(user.getUsername());
		Map map = new HashMap<String, String>();
		map.put("username", user.getUsername());
		map.put("password", user.getPassword());
		map.put("clientip", user.getRegisterip());
		map.put("clientmac", user.getClientmac());
		map.put("secretkkey", user.getSecretkkey());
		map.put("agentlevel", user.getAgentlevel());
		map.put("logid", logid.toString());
		return map;
	}
	
	@SuppressWarnings("unchecked")
	public static T_agentaccountinfo getClientUser(T_agentaccountinfo user){
		T_agentaccountinfo agent = new T_agentaccountinfo();
		agent.setUsername(user.getUsername());
		agent.setPassword(user.getPassword());
		return agent;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}	
